//
//  data.m
//  iCodeMacRun
//
//  Created by Andrew Barry on 6/06/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "data.h"

static JSBool dataConstructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
	return JS_TRUE;
}

static void dataFinalizer(JSContext *cx, JSObject *obj) {
}

static JSClass dataClass = {"DataObject", JSCLASS_HAS_RESERVED_SLOTS(2), 
JS_PropertyStub,JS_PropertyStub,JS_PropertyStub,JS_PropertyStub, 
JS_EnumerateStub,JS_ResolveStub,JS_ConvertStub,dataFinalizer 
};

static JSPropertySpec dataProps[] = {
{0, 0, 0, 0, 0}
};

static JSFunctionSpec dataFunctions[] = {
{0, 0, 0, 0, 0}
};

static JSObject *dataObject;

void registerData(JSContext *cx, JSObject *global) {
	JS_AddRoot(cx, &dataObject);
	
	dataObject = JS_InitClass(cx, global, NULL, &dataClass,
							   dataConstructor, 0,
							  dataProps,
							  dataFunctions, 
							   NULL, NULL);
}

JSObject *createDataObjectForWindow(JSObject *target) {
	JSObject *obj = nil;
	
	JS_GC(cx);
	JS_AddRoot(cx, &obj);
	
	obj = JS_NewObject(cx, &dataClass, dataObject, nil);
//	ActionBridge *bridge = [[ActionBridge alloc] initWithObject:obj withEvent:@"Action" withContext:cx withTarget:target];
//	JS_SetReservedSlot(cx, obj, 0, INT_TO_JSVAL(0));
//	JS_SetReservedSlot(cx, obj, 1, INT_TO_JSVAL((int) bridge));
	
	JS_RemoveRoot(cx, &obj);
	
	return obj;
}
